package ee.az.test.gui.event;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MouseEventViewer extends Frame {

	private static final long serialVersionUID = 1L;
	private TextArea console;
	
	public MouseEventViewer() throws HeadlessException {
		super();
		this.console = new TextArea();
		
		addWindowListener(new WListener());
		
		setLayout(new BorderLayout());
		add(console, BorderLayout.CENTER);
		add(new MListener(), BorderLayout.NORTH);
		
		setBounds(new Rectangle(new Point(128, 64), new Dimension(512, 378)));
		setVisible(true);
	}

	private void println(String msg) {
		console.append(msg);
		console.append("\n");
	}

	public static void main(String[] args) {
		new MouseEventViewer();
	}

	private class MListener extends Panel implements MouseListener, MouseWheelListener {
		private static final long serialVersionUID = 1L;
		public MListener() {
			addMouseListener(this);
			addMouseWheelListener(this);
		}
		@Override
		public Dimension getPreferredSize() {
			return new Dimension((int)super.getPreferredSize().getWidth(), 64);
		}
		public void mouseClicked(MouseEvent e) {
			println(e.toString());
		}
		public void mouseEntered(MouseEvent e) {
			println(e.toString());
		}
		public void mouseExited(MouseEvent e) {
			println(e.toString());
		}
		public void mousePressed(MouseEvent e) {
			println(e.toString());
		}
		public void mouseReleased(MouseEvent e) {
			println(e.toString());
		}
		public void mouseWheelMoved(MouseWheelEvent e) {
			println(e.toString());
		}
	}

	private class WListener extends WindowAdapter {
		@Override
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}
	
}
